﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Othello_Game
{
    /// <summary>
    /// A class used to specify a 2 dimentional position on the gameboard (visual or logical)
    /// </summary>
    public class Position
    {
        #region Public Properties
        /// <summary>
        /// The row number of the position
        /// </summary>
        public int Row { get; set; }
        /// <summary>
        /// The Column number of the position
        /// </summary>
        public int Column { get; set; }
        #endregion

        #region Ctors
        /// <summary>
        /// Initialize a new instance of the Othello_Game.Position class.
        /// </summary>
        public Position()
        {
            this.Row = 0;
            this.Column = 0;
        }

        /// <summary>
        /// Initialize a new instance of the Othello_Game.Position class.
        /// </summary>
        /// <param name="row">The row value</param>
        /// <param name="col">The column value</param>
        public Position(int row, int col)
        {
            this.Row = row;
            this.Column = col;
        }

        /// <summary>
        /// Initialize a new instance of the Othello_Game.Position class.
        /// </summary>
        /// <param name="pos"></param>
        public Position(Position pos)
        {
            this.Row = pos.Row;
            this.Column = pos.Column;
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Return true if the position is at one of the corners.
        /// </summary>
        /// <returns></returns>
        public bool IsCornerPosition()
        {
            bool isCorner = false;

            if (this.Row == 0)
            {
                if (this.Column == 7 || this.Column == 0)
                {
                    isCorner = true;
                }
            }
            else if (this.Row == 7 )
            {
                if (this.Column == 7 || this.Column == 0)
                {
                    isCorner = true;
                }
            }

            return isCorner;
        }

        #endregion

        #region Object Class methods
        /// <summary>
        /// This is an Object Class method, Overrided for improving performance of 
        /// Hash Tables and dictionaries Strautures.
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return (this.Column * 10) + this.Row;
        }

        /// <summary>
        /// This is an Object Class method, Overrided for improving performance of 
        /// Hash Tables and dictionaries Strautures.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            bool isEqual = false;

            if ((obj == null) || (this.GetType() != obj.GetType()))
            {
                isEqual = false;
            }
            else
            {
                Position position = obj as Position;
                if (position != null)
                {
                    isEqual = (position.Row == this.Row) && (position.Column == this.Column);
                }
            }

            return isEqual;
        }
        #endregion
    }
}
